<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:cc="http://java.sun.com/jsf/composite"
	xmlns:hmrList="http://java.sun.com/jsf/composite/list"
	xmlns:hmrDetail="http://java.sun.com/jsf/composite/detail"
	xmlns:hmrSearch="http://java.sun.com/jsf/composite/search"	>

<cc:interface>
	<cc:attribute name="handler"				type="com.hemerasolutions.v2trainer.component.interfaces.list.StepListLevelsInterface" />
	<cc:attribute name="enabled" 				type="java.lang.Boolean"	default="true"  />
	<cc:attribute name="importSteps" 			type="java.lang.Boolean"	default="true"  />
	<cc:attribute name="addGenerics" 			type="java.lang.Boolean"	default="true"  />
</cc:interface>

<cc:implementation>

	<script type="text/javascript">
		function customToggler(ui){
			if($(ui).hasClass('ui-expanded')){
				$(ui).removeClass('ui-expanded');	
				$(ui).find(".ui-toggler-status").removeClass("ui-icon-triangle-1-s");
				$(ui).find(".ui-toggler-status").addClass("ui-icon-triangle-1-e");
			}else{
				$(ui).addClass('ui-expanded');	
				$(ui).find(".ui-toggler-status").removeClass("ui-icon-triangle-1-e");
				$(ui).find(".ui-toggler-status").addClass("ui-icon-triangle-1-s");
			}};	
	</script>
	

	<span id="#{cc.clientId}" >

		<p:accordionPanel id="levelsTable" styleClass="ui-trainingLevelTable" dynamic="true" style="width:100%;min-width:740px;">
		    <c:forEach items="#{cc.attrs.handler.stepListHandlers}" var="stepListHandler" varStatus="loop" >
		        <p:tab title="#{msgs[stepListHandler.stepLevel.levelName]}" >
					<f:subview id="tab_#{loop.index}">
						<h:form prependId="false" onkeypress="if( event.keyCode == 13){event.keyCode=0;}">
							<h:panelGrid columns="7"  rendered="#{cc.attrs.enabled}">
								<p:commandButton value="#{msgs.AddRestInterval}"	update="stepLevelPanel"	actionListener="#{cc.attrs.handler.addStep}" 
									 process="@this" >
									<f:attribute name="stepType" 			value="4"/>	
									<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
								</p:commandButton>
								<p:menuButton id="menubutton" value="#{msgs.AddGroup}" rendered="#{cc.attrs.enabled}"   > 	
									<p:menuitem value="#{msgs.Warming}"  			update="stepLevelPanel"	actionListener="#{cc.attrs.handler.addStep}">
										<f:attribute name="stepType" 			value="7"/>	
										<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
									</p:menuitem> 	
									<p:menuitem value="#{msgs.MainSeries}"			update="stepLevelPanel"	actionListener="#{cc.attrs.handler.addStep}"> 	
										<f:attribute name="stepType" 			value="8"/>	
										<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
									</p:menuitem> 	
									<p:menuitem value="#{msgs.SecundarySeries}" 	update="stepLevelPanel"	actionListener="#{cc.attrs.handler.addStep}">
										<f:attribute name="stepType" 			value="9"/>	
										<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
									</p:menuitem> 	
									<p:menuitem value="#{msgs.TechniqueSeries}" 	update="stepLevelPanel"	actionListener="#{cc.attrs.handler.addStep}">
										<f:attribute name="stepType" 			value="10"/>	
										<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
									</p:menuitem> 	
									<p:menuitem value="#{msgs.Ending}" 				update="stepLevelPanel"	actionListener="#{cc.attrs.handler.addStep}"> 	
										<f:attribute name="stepType" 			value="11"/>	
										<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
									</p:menuitem> 	
									<p:menuitem value="#{msgs.Anothers}..."	 		update=":#{cc.clientId}:addOtherGroupDialog"		actionListener="#{cc.attrs.handler.addOthersGroup}"	
										oncomplete="addOtherGroupDialog_#{cc.id}.show();">	
										<f:attribute name="stepType" 			value="12"/>	
										<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
										<f:attribute name="panelToUpdate" 		value="#{component.parent.parent.parent.clientId}" />
									</p:menuitem> 	
								</p:menuButton>
								<p:commandButton value="#{msgs.AddSeries}" 				update="stepLevelPanel"	actionListener="#{cc.attrs.handler.addStep}">
									<f:attribute name="stepType" 			value="6"/>	
									<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
								</p:commandButton>	
								<p:commandButton value="#{msgs.AddTemplateExercise}"	update="stepLevelPanel"	actionListener="#{cc.attrs.handler.addStep}"	
									process="@this"	rendered="#{cc.attrs.addGenerics}">
									<f:attribute name="stepType" 			value="2"/>	
									<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
								</p:commandButton>
								<p:menuButton value="#{msgs.Import}" rendered="#{cc.attrs.enabled and cc.attrs.importSteps}"  > 	
									<p:menuitem value="#{msgs.Exercise}" 			actionListener="#{cc.attrs.handler.importStepListener}"	
										update=":#{cc.clientId}:findExerciseDialog" 		oncomplete="wfindExerciseDialog_#{cc.id}.show();">
										<f:attribute name="importType" 			value="A" />
										<f:attribute name="panelToUpdate" 		value="#{component.parent.parent.parent.clientId}" />
										<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
									</p:menuitem> 	
									<p:menuitem value="#{msgs.ExerciseGroup}" 		actionListener="#{cc.attrs.handler.importStepListener}"	
										update=":#{cc.clientId}:findExerciseGroupDialog" 	oncomplete="wfindExerciseGroupDialog_#{cc.id}.show();"  >
										<f:attribute name="importType" 			value="B" />
										<f:attribute name="panelToUpdate" 		value="#{component.parent.parent.parent.clientId}" />
										<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
									</p:menuitem> 	
									<p:menuitem value="#{msgs.TrainingSystem}" actionListener="#{cc.attrs.handler.importStepListener}"	
										update=":#{cc.clientId}:findTrainingSystemDialog"   	oncomplete="wfindTrainingSystemDialog_#{cc.id}.show();"> 	
										<f:attribute name="importType" 			value="C" />
										<f:attribute name="panelToUpdate" 		value="#{component.parent.parent.parent.clientId}" />
									<f:attribute name="stepLevelHandler" 		value="#{stepListHandler}"/>	
									</p:menuitem> 	
									<p:menuitem value="#{msgs.Training}"   		actionListener="#{cc.attrs.handler.importStepListener}"	
										update=":#{cc.clientId}:findTrainingDialog"   	oncomplete="wfindTrainingDialog_#{cc.id}.show();"> 	
										<f:attribute name="importType" 			value="D" />
										<f:attribute name="panelToUpdate" 		value="#{component.parent.parent.parent.clientId}" />
										<f:attribute name="stepLevelHandler" 	value="#{stepListHandler}"/>	
									</p:menuitem> 	
								</p:menuButton>
							    <p:commandButton value="#{msgs.CopyFromLevel}" update=":#{cc.clientId}:copyLevelDialog"  oncomplete="wcopyLevelDialog_#{cc.id}.show();">
									<f:setPropertyActionListener target="#{cc.attrs.handler.stepListHandler}" 	value="#{stepListHandler}"/>
									<f:setPropertyActionListener target="#{cc.attrs.handler.panelToUpdate}" 	value="#{component.parent.parent.clientId}"/>
							    </p:commandButton>
								<p:commandButton value="#{msgs.ReplicateToOthers}" actionListener="#{cc.attrs.handler.copyToAll}" update="@(.ui-training)" rendered="#{stepListHandler.stepLevel.level == 0}">
									<f:attribute name="source" 	value="#{stepListHandler}"/> 
								</p:commandButton>
		
							</h:panelGrid>
							<p:outputPanel id="stepLevelPanel" layout="block">
								<hmrList:stepListComp 	handler="#{stepListHandler}" enabled="#{cc.attrs.enabled}"
														isTrainingSystem="#{not cc.attrs.importSteps}"
														onIzPopUp="wintensityZoneList_#{cc.id}.show();"	
														onImzPopUp="wmodalityIZList_#{cc.id}.show();"
														onStatistiUPopUp="wstatisticUnitDialog_#{cc.id}.show();"
														/>
							</p:outputPanel>
						</h:form>
					</f:subview>
		        </p:tab>
		    </c:forEach>
		</p:accordionPanel>

	
	</span>

	<p:dialog id="copyLevelDialog" header="#{msgs.CopyIntensityZones}"  modal="true" appendTo="@(body)"  widgetVar="wcopyLevelDialog_#{cc.id}" > 
		<h:form prependId="false">
			<p:dataTable   value="#{cc.attrs.handler.stepLevels}" var="stepLevel" paginator="true"  
				paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="8" emptyMessage="#{msgs.NoResults}" >   
				<p:columnGroup type="header" >  
					<p:row>
						<p:column	colspan="2" >
							<f:facet name="header">
								<h:outputText value="#{msgs.Name}"/>
							</f:facet>
						</p:column>
					</p:row>	 
				</p:columnGroup>
				<p:column colspan="1" headerText="#{msgs.Name}" rendered="#{stepLevel != cc.attrs.handler.stepListHandler.stepLevel}"   >
					<h:outputText value="#{msgs[stepLevel.levelName]}" />
				</p:column>
				<p:column colspan="1" styleClass="ui-table-button-row"  rendered="#{stepLevel != cc.attrs.handler.stepListHandler.stepLevel}"   >
					<p:commandButton  title="#{msgs.Copy}" icon="ui-icon-copy" actionListener="#{cc.attrs.handler.copyLevel}" 
						 oncomplete="wcopyLevelDialog_#{cc.id}.hide();"   styleClass="ui-table-button" process="@this" update="@(.ui-training)" >
						<f:attribute name="source"  		value="#{stepLevel}"/> 
					</p:commandButton>
				</p:column>
			</p:dataTable>	
		</h:form>
	</p:dialog>
	
	<p:dialog id="addOtherGroupDialog" header="#{msgs.ExerciseGroupDetails}" modal="true" appendTo="@(body)" widgetVar="addOtherGroupDialog_#{cc.id}">
		<h:form prependId="false">
			<h:panelGrid columns="2"> 
				<h:outputLabel value="#{msgs.Name} :" for="groupName"/>
				<p:inputText id="groupName" value="#{cc.attrs.handler.stepListHandler.step.name}" />
			</h:panelGrid>
					
			<p:commandButton value="#{msgs.Ok}" oncomplete="addOtherGroupDialog_#{cc.id}.hide();" 
				actionListener="#{cc.attrs.handler.updateCurrentPanel}"/>
		</h:form>	
	</p:dialog>
 		

 	<p:dialog id="findExerciseDialog" header="#{msgs.FindExercises}" modal="true" appendTo="@(body)"  widgetVar="wfindExerciseDialog_#{cc.id}">
		<hmrSearch:exerciseSearch handler="#{cc.attrs.handler.exerciseSearchComp}" />
	</p:dialog>


 	<p:dialog id="findExerciseGroupDialog" header="#{msgs.FindExerciseGroups}" modal="true" appendTo="@(body)"  widgetVar="wfindExerciseGroupDialog_#{cc.id}">
		<hmrSearch:exerciseGroupSearch handler="#{cc.attrs.handler.exerciseGroupSearchComp}"/>
			
	</p:dialog>


	<p:dialog id="modalExerciseGroupAdd" header="#{msgs.ExerciseGroup}: #{cc.attrs.handler.exerciseGroup.name}" dynamic="true"
		appendTo="@(body)" modal="true" widgetVar="wmodalExerciseGroupAdd_#{cc.id}" >
		<h:form prependId="false" style="min-width:750px;max-width:750px;height:95%;margin-left:20px;margin-right:20px;">
			<p:tabView id="groupAddTabView" style="min-width:740px;max-width:740px" >
				<p:ajax event="tabChange" listener="#{cc.attrs.handler.tabExerciseGroupChanged}" update="@form:groupAddTabView:preview" />
				<p:tab title="#{msgs.ExerciseGroup}">
					<p:dataTable value="#{cc.attrs.handler.exerciseGroup.exerciseSubGroups}" var="exerciseSubGroups" paginator="true"  style="min-width:600px"
						paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="8" emptyMessage="#{msgs.NoResults}">   
						<p:columnGroup type="header" >  
							<p:row>
								<p:column colspan="6" style="text-align:center;">
									<f:facet name="header">
										<h:outputText value="#{msgs.ExerciseGroupExercises}" />
									</f:facet>
								</p:column>
							</p:row>
							<p:row>
								<p:column	colspan="2" >
									<f:facet name="header"> 
											<h:outputText value="#{msgs.Name}" style="padding-top:4px"/>
									</f:facet>
								</p:column>
								<p:column	colspan="1" style="padding:0px;margin:0px;">
									<f:facet name="header">
										<h:outputText value="#{msgs.Description}"/>
									</f:facet>
								</p:column>
								<p:column	colspan="1" style="padding:0px;margin:0px;">
									<f:facet name="header">
										<h:outputText value="#{msgs.BodyRegion}"/> 
									</f:facet>
								</p:column>
								<p:column	colspan="1" style="padding:0px;margin:0px;">
									<f:facet name="header">
										<h:outputText value="#{msgs.MuscleGroup}"/>
									</f:facet>
								</p:column>
							</p:row>	 
						</p:columnGroup>
						<p:subTable var="exercise" value="#{exerciseSubGroups.exercises}" >
							<f:facet name="header">
								<h:outputText value="#{exerciseSubGroups.modality.name}" />
							</f:facet>
							<p:column colspan="1" headerText="#{msgs.Name}" >
								<h:outputText value="#{exercise.name}" />
							</p:column>
				
							<p:column colspan="1" styleClass="ui-table-button-row" >
								<p:commandButton action="#{cc.attrs.handler.toViewExercise}"  title="#{msgs.View}" icon="ui-icon-search" 
									update=":#{cc.clientId}:exerciseDialog" oncomplete="wexerciseDialog_#{cc.id}.show()"  styleClass="ui-table-button">
									<f:setPropertyActionListener target="#{cc.attrs.handler.selExercise}" value="#{exercise}"/>
								</p:commandButton>
							</p:column>
				
							<p:column headerText="#{msgs.Description}" >
								<h:outputText value="#{exercise.description}" />
							</p:column>		
				
							<p:column headerText="#{msgs.BodyRegion}" >
								<h:outputText value="#{exercise.bodyRegionsText}" />
							</p:column>		
				
							<p:column headerText="#{msgs.MuscleGroup}" >
								<h:outputText value="#{exercise.muscleGroupsText}" />
							</p:column>		
					
						</p:subTable>	
					</p:dataTable>					
				</p:tab>
				<p:tab title="#{msgs.Settings}"> 
					<hmrList:stepListComp handler="#{cc.attrs.handler.egListHandler}" 			enabled="true"    />
				</p:tab>
				<p:tab title="#{msgs.Preview}" >
					<hmrList:stepListComp id="preview"  handler="#{cc.attrs.handler.egPreviewListHandler}" 	enabled="true"
						onIzPopUp="wintensityZoneList_#{cc.id}.show();"	onImzPopUp="wmodalityIZList_#{cc.id}.show()"/>
				</p:tab>
			</p:tabView>

			<p:commandButton title="#{msgs.Add}" 		value="#{msgs.Add}"  	process="@form"		action="#{cc.attrs.handler.addExerciseGroup}" />
			<p:commandButton title="#{msgs.Refresh}" 	value="#{msgs.Refresh}"	process="@form"		update="@form:groupAddTabView:preview"  	
				action="#{cc.attrs.handler.refreshExerciseGroupPreview}" />

			<p:commandButton value="#{msgs.Cancel }" onclick="wmodalExerciseGroupAdd_#{cc.id}.hide();"	type="button" />
		</h:form>

	</p:dialog>		

	
	<p:dialog id="exerciseDialog" header="#{msgs.Exercise}" modal="true" appendTo="@(body)" widgetVar="wexerciseDialog_#{cc.id}" style="width:90%"> 
		<hmrDetail:exerciseDetails handler="#{cc.attrs.handler.exerciseDetailsHandler}" 
			editable="false"
			intensitySummary="true" />

		<div align="left"   > 
			<p:commandButton type="button" value="#{msgs.Cancel}"		icon="ui-icon-cancel" onclick="wexerciseDialog_#{cc.id}.hide()"/>
		</div>
	</p:dialog>


	<p:dialog id="findTrainingSystemDialog" header="#{msgs.TrainingSystem}"  modal="true" appendTo="@(body)" widgetVar="wfindTrainingSystemDialog_#{cc.id}" >
		<c:if test="#{cc.attrs.importSteps}"   >
			<hmrSearch:trainingSystemSearch handler="#{cc.attrs.handler.tsSearchComp}" showResultsPanel="true"/>
		</c:if>
	</p:dialog>
 		

	<p:dialog id="findModalityDialog" header="#{msgs.Modality}" modal="true" appendTo="@(body)" widgetVar="wfindModalityDialog_#{cc.id}" >
		<c:if test="#{cc.attrs.importSteps}"   >
			<hmrSearch:modalitySearch handler="#{cc.attrs.handler.modalitySearchComp}" showResultsPanel="true"/>
		</c:if>
	</p:dialog>


	<p:dialog id="findTrainingDialog" header="#{msgs.Training}" modal="true" appendTo="@(body)" widgetVar="wfindTrainingDialog_#{cc.id}" >
		<c:if test="#{cc.attrs.importSteps}"   >
			<hmrSearch:trainingSearch handler="#{cc.attrs.handler.trainingSearchComp}" showResultsPanel="true"/>
		</c:if>
	</p:dialog>

	<p:dialog id="statisticUnitDialog" header ="#{msgs.StatisticDetails}" modal="true" appendTo="@(body)" widgetVar="wstatisticUnitDialog_#{cc.id}" styleClass="ui-statisticDetails">
		<c:if test="#{cc.attrs.importSteps}"   >
			<h:form prependId="false">
				<h:outputText value="#{MeasureUnit}: "/>
				<p:selectOneMenu value="#{cc.attrs.handler.statisticHandler.trainingStatistic.volumeFactor}" immediate="true"  converter="#{volumeFactorConverter}"  
					style="min-width:80px">
					<f:selectItems value="#{cc.attrs.handler.statisticHandler.trainingStatistic.volumeType.volumeFactors}"  var="volumeFactor" 
						itemLabel="#{msgs[volumeFactor.name]} " itemValue="#{volumeFactor}" />
					<p:ajax update="@(.statisticTable)"  />	
				</p:selectOneMenu>				
			</h:form>		
		</c:if>
	</p:dialog>


	<p:dialog id="intensityZoneList"  style="width:600px" appendTo="@(body)" widgetVar="wintensityZoneList_#{cc.id}" styleClass="ui-intensityZoneList"> 
		<hmrList:intensityZoneList handler="#{cc.attrs.handler.izHandler}" editable="false" />
	</p:dialog> 	

	<p:dialog id="modalityIZList" style="width:600px" appendTo="@(body)" widgetVar="wmodalityIZList_#{cc.id}" styleClass="ui-modalityIZList">
		<hmrList:modalityIZList handler="#{cc.attrs.handler.imzHandler}" editable="false"/>	
	</p:dialog> 	


</cc:implementation>


</html>